package com.qf.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.qf.pojo.DtsGrouponRules;
import com.qf.service.DtsGrouponRulesService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/groupon")
public class AdminGrouponController {
    @Autowired
    DtsGrouponRulesService grouponRulesService;

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsGrouponRules rules) {
        grouponRulesService.delete(rules);
        return ResponseUtil.ok();
    }

    @PostMapping("/update")
    public Object update(@RequestBody DtsGrouponRules rules) {
        rules = grouponRulesService.update(rules);

        return ResponseUtil.ok(rules);
    }

    @PostMapping("/create")
    public Object create(@RequestBody DtsGrouponRules rules) {
        rules = grouponRulesService.insret(rules);
        return ResponseUtil.ok(rules);
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                       @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
                       String sort,Integer goodsId, String order) {
        Map<String, Object> data = grouponRulesService.selectList(page, limit, sort,goodsId, order);
        return ResponseUtil.ok(data);
    }
}
